package com.example.yoga.mapper;

import com.example.yoga.entity.MonthMoney;
import com.example.yoga.entity.PayRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.yoga.entity.PaymentVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author liwenkai
 * @since 2021-03-11
 */
@Mapper
public interface PayRecordMapper extends BaseMapper<PayRecord> {

    @Select("SELECT userName,pay_record.userId,pay_record.payNo,pay_record.payAmount,pay_record.payDate,pay_record.payStatus\n" +
            "FROM pay_record,`user` WHERE pay_record.userId=`user`.userId")
    List<PaymentVo> getPayList();

    @Select("SELECT userName,pay_record.userId,pay_record.payNo,pay_record.payAmount,pay_record.payDate,pay_record.payStatus\n" +
            "FROM pay_record,`user` WHERE pay_record.userId=`user`.userId AND `user`.userName=#{name}")
    List<PaymentVo> getPayListByName(String name);

    @Select("SELECT MONTH(payDate) AS Month,SUM(payAmount) AS Money FROM `pay_record` WHERE payStatus='已审核' GROUP BY MONTH(payDate) ORDER BY  payDate DESC LIMIT 5")
    List<MonthMoney> getMoneyByMonth();
}
